import {reqGetTradeMark,reqAddTradeMark,reqEditTrademark,reqDeleteTrademark} from '@/api/produce/trademark'
const state={
    trademarkInfo:{}
}
const actions={
    // 获取品牌列表
    async getTrademarkList({commit},params){
        const result = await reqGetTradeMark(params)
        if(result.code === 200){
            commit('GETTRADEMARKLIST',result.data)
            return 'ok'
        }else return Promise.reject(new Error('获取品牌列表失败'))
    },
    // 添加品牌
    async addTrademark({commit},params){
        const result = await reqAddTradeMark(params)
        if(result.code===200) return 'ok'
        else return Promise.reject(new Error('添加品牌失败'))
    },
    // 修改品牌
    async editTrademark({commit},params){
      const result = await reqEditTrademark(params)
      if(result.code===200) return 'ok'
      else return Promise.reject(new Error('修改品牌失败'))
    },
    // 删除品牌
    async deleteTrademark({commit},params){
        const result = await reqDeleteTrademark(params)
        console.log(result);
        if(result.code===200) return 'ok'
        else return Promise.reject(new Error('删除品牌失败'))
    }
}
const mutations={
    GETTRADEMARKLIST(state,trademarkInfo){
        state.trademarkInfo = trademarkInfo
    }
}

export default {namespaced: true,state,actions,mutations}